package com.shuang.controller;

import com.shuang.common.RespBean;
import com.shuang.pojo.Area;
import com.shuang.pojo.Person;
import com.shuang.service.AreaServiceImpl;
import com.shuang.service.PersonServiceImpl;
import com.shuang.service.impl.AreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @DATE: 2021/09/26 16:35
 * @Author: 小爽帅到拖网速
 */

@RestController
@CrossOrigin
@Slf4j
public class CheckInfoEntry {

  @Autowired
  PersonServiceImpl personService;

  @Autowired
  AreaServiceImpl areaService;

  @PostMapping("/checkin")
  public RespBean checkin(@RequestBody Person person, @RequestParam("areaName") String areaName, HttpServletRequest request) {
    log.info((String) request.getSession().getAttribute("flag"));
    log.info(person.toString());
    if (!person.getUid().equals("") && StringUtils.hasText(person.getUname())) {

      String areaId = areaService.getAreaIdByAreaName(areaName);
      person.setJkm(((String) request.getSession().getAttribute("flag")));
      person.setAreaNo(areaId);
      personService.save(person);
    }

    return new RespBean().setCode(200).setMessgae("success");
  }

}
